package copyengine.ui.component.button.animation.pc
{
	import com.greensock.TweenLite;
	
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	import copyengine.ui.component.button.animation.ICEButtonAnimation;

	public class CEButtonTweenAnimation implements ICEButtonAnimation
	{
		/**
		 * define how long the tween is.
		 */
		private static const TWEEN_TIME:Number = 0.2;

		/**
		 * button skin maybe scaled  so need an value to remember the button initial value .
		 */
		private var normalScaleX:Number;
		private var normalScaleY:Number;

		private var rollOverScale:Number;

		protected var buttonBg:DisplayObject;

		public function CEButtonTweenAnimation(_args:Object = null)
		{
			rollOverScale = 1.1;
			if (_args != null)
			{
				if (_args["rollOverScale"] != null)
				{
					rollOverScale = _args["rollOverScale"]
				}
			}
		}

		public function setTarget(_buttonBg:DisplayObject):void
		{
			buttonBg = _buttonBg;
			normalScaleX = buttonBg.scaleX;
			normalScaleY = buttonBg.scaleY;
		}

		public function dispose():void
		{
			TweenLite.killTweensOf(buttonBg, true);
			buttonBg.scaleX = normalScaleX;
			buttonBg.scaleY = normalScaleY;
			buttonBg = null;
		}

		public function onMouseUp(e:MouseEvent):void
		{
			TweenLite.killTweensOf(buttonBg);
			TweenLite.to(buttonBg, TWEEN_TIME, {scaleX:normalScaleX * rollOverScale, scaleY:normalScaleY * rollOverScale});
		}

		public function onMouseDown(e:MouseEvent):void
		{
			TweenLite.killTweensOf(buttonBg);
			TweenLite.to(buttonBg, TWEEN_TIME, {scaleX:normalScaleX, scaleY:normalScaleY});
		}

		public function onMouseRollOver(e:MouseEvent):void
		{
			TweenLite.killTweensOf(buttonBg);
			TweenLite.to(buttonBg, TWEEN_TIME, {scaleX:normalScaleX * rollOverScale, scaleY:normalScaleY * rollOverScale});
		}

		public function onMouseRollOut(e:MouseEvent):void
		{
			TweenLite.killTweensOf(buttonBg);
			TweenLite.to(buttonBg, TWEEN_TIME, {scaleX:normalScaleX, scaleY:normalScaleY});
		}
	}
}
